package cn.sylinx.horm.spring.boot;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import cn.sylinx.horm.core.SqlClient;
import cn.sylinx.horm.util.GLog;

@Configuration
@ConditionalOnProperty(prefix = "horm", name = "enable", havingValue = "true", matchIfMissing = true)
@Conditional(SqlClientUseNativeCondition.class)
@EnableConfigurationProperties(HORMBootConfig.class)
@Import({ AutoConfiguredCommandScannerRegistrar.class, AutoConfiguredModelScannerRegistrar.class,
        AutoConfiguredMapperScannerRegistrar.class })
public class SqlClientUseNativeAutoConfiguration {

    /**
     * 不使用spring数据源
     * 
     * @param bootConfig
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public SqlClient sqlClientUseNative(HORMBootConfig bootConfig) {
        GLog.debug("SqlClient[UseNative] inited begin..");
        SqlClient sqlClient = new SqlClientInitByNative().setBootConfig(bootConfig).create();
        GLog.info("SqlClient[UseNative] inited done");
        return sqlClient;
    }
}
